#include "comm.hpp"

#include <cstring>

extern Log log;

int main()
{
    //申请共享内存
    int shmid = Share_Memory::get();
    //挂接共享内存
    char* shmaddr = Share_Memory::load(shmid);

    int fd = FIFO::open_write(FIFO_FILE);

    //进程通信代码
    while (true)
    {
        char sign = 'c';
        std::cout << "Please Enter: ";
        // char buffer[1024] = { 0 };
        // fgets(buffer, sizeof(buffer), stdin);
        // memcpy(shmaddr, buffer, strlen(buffer) + 1);
        fgets(shmaddr, 4095, stdin);
        shmaddr[strlen(shmaddr) - 1] = '\0';
        write(fd, &sign, sizeof(sign));
    }
    close(fd);

    //去关联共享内存
    Share_Memory::unload(shmaddr);

    return 0;
}
